package leecode;

import java.util.Arrays;

public class _733 {
    public static int[][] floodFill(int[][] image, int sr, int sc, int color) {
        fun(image, sr, sc, color, image[sr][sc]);
        return image;
    }

    private static void fun(int[][] image, int sr, int sc, int color, int num) {
        if (sr < 0 ||
                sc < 0 ||
                sr >= image.length ||
                sc >= image[0].length ||
                image[sr][sc] == color) {
            return;
        }
        if (image[sr][sc] == num) {
            image[sr][sc] = color;
            //上
            fun(image, sr - 1, sc, color, num);
            //下
            fun(image, sr + 1, sc, color, num);
            //左
            fun(image, sr, sc - 1, color, num);
            //右
            fun(image, sr, sc + 1, color, num);
        }

    }

    public static void main(String[] args) {
        int[][] image = new int[][]{{0, 0, 0}, {0, 0, 0}};
        int[][] image1 = floodFill(image, 0, 0, 0);
        System.out.println(Arrays.deepToString(image1));
    }
}
